# Convention for naming variables
# *_DIR : designate the NAME of a directory
# *_PATH : designate the PATH to a DIR
#
# This makefile is used to do the necessary calls to cmake in order to build
# for different platforms.
# It also include targets that match standard cmake Makefile traget

# Project name passed to CMake (stop process if not defined)
PROJECT_NAME= PROJECT_NAME

#############
# DIR NAMES #
#############
# Main dir names
SOURCE_DIR= Source/${PROJECT_NAME}
PROJECT_DIR= Projects
# Dir name for products
LIB_DIR= Bin
# Dir names for build files
BUILD_DIR= ${PROJECT_DIR}/CMake
XCODE_DIR= ${PROJECT_DIR}/XCode2

########
# PATH #
########
# Indirection lvl used to define path (lead to project root)
INDIRECTION_LVL = ../..
PRODUCT_INDIRECTION_LVL= ../..
CMAKE_INDIRECTION_LVL = ../../..
# Path relative to this makefile
BUILD_PATH= ${INDIRECTION_LVL}/${BUILD_DIR}/${PROJECT_NAME}
XCODE_PATH= ${INDIRECTION_LVL}/${XCODE_DIR}/${PROJECT_NAME}
SOURCE_PATH= ${INDIRECTION_LVL}/${SOURCE_DIR}
# Paths relative to CMake build dir
CMAKE_SOURCE_PATH= ${CMAKE_INDIRECTION_LVL}/${SOURCE_DIR}
# Path to products
LIB_PATH= ${PRODUCT_INDIRECTION_LVL}/${LIB_DIR}
TARGETS= ${LIB_PATH}/lib${PROJECT_NAME}.a
# Other paths
SCRIPTS_PATH= ${INDIRECTION_LVL}/Scripts

#########################
# CMake options a flags #
#########################
CMAKE_FLAGS= 


# MAKE TARGETS
all: compile

compile: configure
	@make -C ${BUILD_PATH}

configure:
	@${SCRIPTS_PATH}/guarantdir ${BUILD_PATH}
	@cd ${BUILD_PATH} && cmake ${CMAKE_FLAGS} ${CMAKE_SOURCE_PATH}

xcode:
	@${SCRIPTS_PATH}/guarantdir ${XCODE_PATH}
	@cd ${XCODE_PATH} && cmake ${CMAKE_FLAGS}  -GXcode ${CMAKE_SOURCE_PATH}

clean:
	rm -rf ${BUILD_PATH}/*
	rm -rf ${XCODE_PATH}/*

proper: clean
	rm -f ${TARGETS}
